<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1 user-scalable=nouser-scalable=no" >
    <title>yejq online judge</title>

    <!-- Bootstrap -->
    <link href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="{{static_url("css/main.css")}}" rel="stylesheet">
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
	<script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
	<script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->
  </head>
  <body>

    <!-- start navagation -->
    <nav class="navbar navbar-default navbar-fixed-bottomnavbar-fixed-bottom" role="navigation" id="navigation">
      <div class="container-fluid">
	<!-- Brand and toggle get grouped for better mobile display -->
	<div class="navbar-header">
	  <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
	  </button>
	  <a class="navbar-brand" href="/">YOJ</a>
	</div>

	<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
    <ul class="nav navbar-nav">
            <li><a href="/" class="tooltip-test" data-toggle="tooltip" data-placement="bottom" title="Home page">Home</a></li>
            <li><a href="/questions" class="tooltip-test" data-toggle="tooltip" data-placement="bottom" title="List of Questions">Questions</a></li>
            <li><a href="/contest" class="tooltip-test" data-toggle="tooltip" data-placement="bottom" title="Current Contests">Contest</a></li>
            <li><a href="/rank" class="tooltip-test" data-toggle="tooltip" data-placement="bottom" title="RankList">Rank</a></li>
            {% if user.authority >= 2 %}
            <li><a href="/design" class="tooltip-test" data-toggle="tooltip" data-placement="bottom" title="Question Design">Design</a></li>
            {% end %}
            {% if user.authority == 3 %}
            <li><a href="/admin" class="tooltip-test" data-toggle="tooltip" data-placement="bottom" title="Administration">Admin</a></li>
            {% end %}
            <li><a href="/logout" class="tooltip-test" data-toggle="tooltip" data-placement="bottom" title="Logout">Logout</a></li>
    </ul>
	  
          <form class="navbar-form navbar-right" role="search">
            <div class="form-group">
              <input type="text" class="form-control" placeholder="Search Problem" id="search">&nbsp&nbsp<a href="/"><span class="glyphicon glyphicon-search"></a>  <!--这里需要修改-->
            </div>
          </form>
	  <div class="navbar-right nav navbar-nav">
	    <p class="navbar-text">Hello,  {{user.nickname}}</p>
	  </div>
	</div><!-- /.container-fluid -->
    </nav>

    <!-- end navigation  -->


    <!-- start main-->
    {% if user.authority == 3 %}
  <div class="container">

    <ul class="nav nav-tabs" role="tablist">
      <li role="presentation" class="active"><a href="#status" aria-controls="home" role="tab" data-toggle="tab">Status</a></li>
      <li role="presentation"><a href="#questions" aria-controls="profile" role="tab" data-toggle="tab">Questions</a></li>
      <li role="presentation"><a href="#users" aria-controls="profile" role="tab" data-toggle="tab">Users</a></li>
    </ul>

    <div class="tab-content">
      <br>
      <div role="tabpanel" class="tab-pane fade in active" id="status">
 			<div class="panel panel-primary">
 				<div class="panel-heading">Status</div>
  				<table class="table">
  					<tr>
  					<th width="15%" id="place_center">RunId</th>
						<th width="15%" id="place_center">QusetionId</th>
						<th width="15%" id="place_center">ContestId</th>
            <th width="15%" id="place_center">Author</th>
            <th width="15%" id="place_center">Statu</th>
						<th width="25%" id="place_center">Operation</th>
  					</tr>
            {% for statu in status %}
  					<tr>
  						<td id="place_center">{{statu.runid}}</td>
  						<td id="place_center">{{statu.pid}}</td>
  						<td id="place_center">{{statu.cid}}</td>
  						<td id="place_center">{{statu.author}}</td>
              <td id="place_center">{{statu.statu}}</td>
              <td id="place_center">
              {% if statu.statu == "waiting" %}
  						<a class="btn btn-danger" role="button" href="/judge?operation=kill&runid={{statu.runid}}&pid={{statu.pid}}&statu={{statu.statu}}">Kill</a>
              {% else %}
              <a class="btn btn-info" role="button" href="/judge?operation=rejudge&runid={{statu.runid}}&pid={{statu.pid}}&statu={{statu.statu}}">Rejudge</a>
              {% end %}
              </td>
  					</tr>
            {% end %}
  				</table>
      </div>
    </div>
    <br>
      <div role="tabpanel" class="tab-pane fade" id="users">
          <table class="table">
            <tr>
            <th width="8%" id="place_center">UId</th>
            <th width="8%" id="place_center">Auth.</th>
            <th width="13%" id="place_center">RegTime</th>
            <th width="7%" id="place_center">Uname</th>
            <th width="10%" id="place_center">Nickname</th>
            <th width="8%" id="place_center">Submit</th>
            <th width="8%" id="place_center">Accepted</th>
            <th width="8%" id="place_center">Status</th>
            <th width="10%" id="place_center">Sex</th>
            <th width="10%" id="place_center">Phone</th>
            <th width="10%" id="place_center">Email</th>
            </tr>
            {% for auser in users %}
            <tr>
              <td id="place_center">{{auser.uid}}</td>
              <td id="place_center">{{auser.authority}}</td>
              <td id="place_center">{{auser.register_time}}</td>
              <td id="place_center">{{auser.username}}</td>
              <td id="place_center">{{auser.nickname}}</td>
              <td id="place_center">{{auser.submit}}</td>
              <td id="place_center">{{auser.accepted}}</td>
              <td id="place_center">{{auser.status}}</td>
              <td id="place_center">{{auser.sex}}</td>
              <td id="place_center">{{auser.phone}}</td>
              <td id="place_center">{{auser.email}}</td>
            </tr>
            {% end %}
          </table>
      </div>

      <div role="tabpanel" class="tab-pane fade" id="questions">
      <div class="panel panel-primary">
        <div class="panel-heading">Question List</div>
          <table class="table">
            <tr>
              <th width="15%" id="place_center">Id</th>
            <th width="15%" id="place_center">Title</th>
            <th width="15%" id="place_center">Accepted</th>
            <th width="15%" id="place_center">Submit</th>
            <th width="10%" id="place_center">Ratio</th>
            <th width="10%" id="place_center">Difficulty</th>
            <th width="10%" id="place_center">Source</th>
            <th width="10%" id="place_center">Opertion</th>
            </tr>
            {% for question in questions %}
            <tr>
              <td id="place_center">{{question.pid}}</td>
              <td id="place_left"><a href="/questions?query={{question.pid}}">{{question.title}}</a></td>
              <td id="place_center">{{question.accepted}}</td>
              <td id="place_center">{{question.submit}}</td>
              {% if question.submit != 0%}
              <td id="place_center">{{'%.2f' % (float(question.accepted)/(question.submit) * 100)}}%</td>
              {% else %}
              <td id="place_center">0.0%</td>
              {% end %}
              <td id="place_center">{{question.difficulty}}</td>
              <td id="place_center">
                        <!-- Button trigger modal -->
          <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal{{question.pid}}">
            Source
          </button>

          <!-- Modal -->
          <div class="modal fade" id="myModal{{question.pid}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
              <div class="modal-content">
                <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                  <h4 class="modal-title" id="myModalLabel">View Sorce Code</h4>
                </div>
                <div class="modal-body">
                  <pre id="place_left">{{question.source}}</pre>
                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
              </div>
            </div>
          </div>
        </td>
              <td id="place_center">
                {% if question.valid == 0 %}
                <a class="btn btn-success" role="button" href="/judge?operation=validate&pid={{question.pid}}">Validate</a>
                {% else %}
                <a class="btn btn-danger" role="button" href="/judge?operation=invalidate&pid={{question.pid}}">Invalidate</a>
                {% end %}
              </td>
            </tr>
            {% end %}
          </table>
</div>
      </div>
  </div>
		</div>
    {% else %}
    <div class="container">
      <div class="alert alert-danger" role="alert">Insufficient permissions</div>
    </div>
    {% end %}
	<!-- end main-->

    <div class="container">
      <div class="footer">
	<span> powered by yejq 2015</span>
      </div>
    </div>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script>
    <script src="{{static_url("js/main.js")}}"></script>

  </body>
</html>
